// pages/myBiddings/myBiddings.js
var count_down = require('../../utils/countDown.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    host: getApp().globalData.host,
    page: {
      pageNo: 1,
      pageSize: 8
    },
    queryStatus: '',
    biddings: [],
    hidden: false,
    scrollTop: 0,
    scrollHeight: 0,
    hasMore: true,
    countDown:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          scrollHeight: res.windowHeight
        });
      }
    });
    this.queryBidding();
  },
  queryBidding:function(){
    var that = this;
    wx.request({
      url: getApp().globalData.host + 'bizportal/my/phone/bidding/list',
      data: { pageSize: that.data.page.pageSize, pageNo: that.data.page.pageNo},
      header: getApp().globalData.header,
      method: 'POST',
      success: function (res) {
        var biddings = that.data.biddings;
        if (res.data.results == '' || res.data.results == null || typeof(res.data.results)=='undefined' ||res.data.results.length==0) {
          that.setData({
            hasMore: false
          });
          if(biddings.length>0)
            return;
        }
        for (var i = 0; i < res.data.results.length; i++) {
          count_down.countDown('',res.data.results[i].expireTime,that,res.data.results[i].biddingCode);
          biddings.push(res.data.results[i]);
        }
        that.data.page.pageNo++;
        that.setData({
          biddings: biddings,
          hidden: true,
          hasMore:true
        });
      },
      fail: function (res) {},
      complete: function (res) {}
    })    
  },
  //查看订单详情
  getOrderDetail: function (event) {
    var orderId = event.currentTarget.dataset.orderId;
    wx.navigateTo({
      url: '../order/order?orderId=' + orderId,
    })
  },
  //页面滑动到底部
  bindDownLoad: function () {
if (this.data.hasMore) {
      this.queryBidding();
      //查询期间设置为不得再次查询
      this.setData({
        hasMore: false
      });

    }
  },
  biddingDetail:function(event){
    var biddingId = event.currentTarget.dataset.biddingId;
    wx.navigateTo({
      url: '../bidding/bidding?biddingId=' + biddingId,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})